package com.dddpeter.app.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class CommonInteceptor implements HandlerInterceptor {
	private static final Logger  LOG = Logger.getLogger(CommonInteceptor.class);
	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object obj, Exception ex)
			throws Exception {

	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object obj, ModelAndView mav)
			throws Exception {

	}

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object obj) throws Exception {
		HttpSession session = request.getSession();
		if (session.getAttribute("user") != null) {
			
			return true;
		} else {
			response.sendRedirect("login.do");
			LOG.info("用户未登录或者登陆超时");
			return false;
		}

	}

}
